<template>
  <div>
    <el-card>
      <el-upload
        class="upload-demo"
        action="https://47.96.182.33:8080/file/uploadFile"
        :show-file-list="false"
        :http-request="uploadMyFile"
      >
        <el-button type="primary">上传作业文件</el-button>
      </el-upload>
      <el-button style="margin-top: 10px" @click="handleSubmitWork()" >提交</el-button>
    </el-card>
    <!--
    <el-table
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column type="index" label="序号" min-width="40" align="center" />
      <el-table-column
        prop="qtid"
        label="类型ID"
        min-width="40"
      />
      <el-table-column
        prop="questionName"
        label="题目名称"
        min-width="120"
      />
      <el-table-column
        prop="questionContent"
        label="题目内容"
        min-width="120"
      />
      <el-table-column
        prop="url"
        label="题目文件"
        min-width="120"
      >
        <template slot-scope="scope">
          {{ scope.row.url ? scope.row.url :'暂无' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="addingTime"
        label="添加时间"
        min-width="120"
      />
    </el-table>
-->
  </div>

</template>
<script>
import { getQuestionList, submitHomeWork } from '../../api/work'
import {uploadFile} from '@/api/upload'
export default {
  components: {},
  data() {
    return {
      tableData: [],
      page: {
        pageNum: 1,
        pageSize: 10,
        totalPage: 0,
        totalSize: 0
      },
      url: ''
    }
  },
  created() {
   // this.getList()
    this.qid = this.$route.query.qid
    this.tid = this.$route.query.tid

  },
  methods: {
    getList() {
      const qid = this.$route.query.qid
      getQuestionList({
        qid: qid,
        pageNum: this.page.pageNum,
        pageSize: this.page.pageSize
      }).then(res => {
        this.tableData = res.data.list
        this.page = res.data.page
      }).catch(err => {
        this.$message.error('请求失败！')
      })
    },
    uploadMyFile(param){
      var that = this;
      var formData = new FormData();
      formData.append('file',param.file);
      uploadFile(formData).then(res => {
        this.url = res.data
        that.$message.success('上传成功！')
      }).catch(err => {
        that.$message.error('请求失败！')
      })
    },
    handleSubmitWork() {
      submitHomeWork({
        qid: this.qid,
        submitHomeworkFile: this.url,
        tid:this.tid
      }).then(res => {
        this.$message.success('提交成功1')
      }).catch(err => {
        this.$message.error('请求失败！')
      })
    }
  }
}
</script>

<style scoped>

</style>
